<template>
  <div class="_wz_cent_main _wz_trainingSyllabus">
    <Card dis-hover :bordered="true" style="margin:0 0 10px;">
      <p slot="title">搜索</p>

      <Form :model="formDataSearch" ref="formDataSearch" label-position="right" :label-width="100" inline :rules="ruleValidate">
        <FormItem label="运输企业" prop="deptUuid">
          <i-select v-model="formDataSearch.deptUuid" filterable placeholder="请选择运输企业" clearable>
            <Option v-for="item in subDeptList" :value="item.deptUuid" :key="item.deptUuid">{{ item.deptName }}</Option>
          </i-select>
        </FormItem>
        <FormItem label="年份选择" prop="wzCreateYear">
          <DatePicker type="year" v-model="formDataSearch.wzCreateYear" placeholder="请选择年份"></DatePicker>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="searchSubmit('formDataSearch')">搜索</Button>
        </FormItem>

      </Form>
    </Card>

    <Card dis-hover :bordered="true">
      <p slot="title">列表</p>
      <p slot="extra">
        <Button type="primary" @click="trainingSyllabusDailyTrai">打印</Button>
      </p>
      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>

    <Drawer title="查看素材" v-model="materialType" width="1000" :draggable="true">
      <materialList v-if="materialType" :materialList="materialList"></materialList>
    </Drawer>



    <Drawer title="大纲详情" v-model="DailyTraiType" width="1000" :draggable="true">
      <DailyTrai v-if="DailyTraiType" :selectData="formDataSearch"></DailyTrai>
    </Drawer>


    <Spin size="large" fix v-if="spinShow"></Spin>


  </div>
</template>
<script>
import materialList from '../public/materialList.vue'
import wzTbale from "../../../components/table/table";
import DailyTrai from './DailyTrai.vue'


export default {
  components: {
    materialList,//查看素材
    wzTbale,//列表
    DailyTrai,//大纲详情
  },
  data() {
    return {
      DailyTraiType:false,//大纲详情
      spinShow:false,//本页加载
      subDeptList: [],//运输企业
      materialList: [],//素材列表 查看素材使用
      materialType: false,//查看素材弹出
      selectData: {},
      formDataSearch: {
        uuid:'',
        wzCreateYear:'',
      },//搜索表单数据
      ruleValidate: {//正则
        uuid: [
          {required: true, message: '请选择运输企业', trigger: 'blur'}
        ],
        wzCreateYear: [
          {type:'date',required: true, message: '请选择年份', trigger: 'blur'}
        ],
      },
      tableData: {
        height: 'auto',//表格高度 auto
        page: false,//分页是否使用
        columns: [//表头数据
          {type: 'index', width: 70, align: 'center', title: '序号'},
          {
            title: '培训周期', minWidth: 120, render: (h, params) => {
              return h('span', params.row.createYear + '年' + params.row.createMonth + '月');
            }
          },
          {title: '培训课程', minWidth: 200, key: 'trainCoursePlanName'},
          {title: '培训类型', minWidth: 110, key: 'trainCoursePlanTypeName'},
          {title: '培训方向', minWidth: 100, key: 'trainCoursePlanDirectionName'},
          {
            title: '随堂测验', minWidth: 160, render: (h, params) => {
              //  0：未开始，1：已完成，-1：进行中
              if (params.row.trainCoursePlanExam == 1) {
                return h('span', params.row.materialExamName)
              } else {
                return h('Tag', {props: {type: 'dot',color: 'default'}}, '未添加')
              }
            }
          },
          {
            title: '课件时长', minWidth: 100, render: (h, params) => {
              return h('span', params.row.trainCoursePlanTotalDuration + '分钟');
            }
          },
          {title: '运输类型', minWidth: 120, key: 'trainCoursePlanTransportTypeName', render: (h, params) => {
              return h('Tag', {props: {color: 'blue'}}, params.row.trainCoursePlanTransportTypeName);
            }
          },
          {title: '课题数量', minWidth: 100, key: 'trainCoursePlanMaterialNumber'},
          {title: '培训时间', minWidth: 180, key: 'trainCoursePlanBeginDate', render: (h, params) => {
              return h('span', params.row.trainCoursePlanBeginDate + ' 至 ' + params.row.trainCoursePlanEndDate);
            }
          },
          {
            title: '操作', fixed: 'right', width: 80,
            render: (h, params) => {
              let operationButtons = [];
              operationButtons.push(h('span', {
                style: {"color": "#2d8cf0", "cursor": "pointer"},
                on: {
                  click: () => {
                    this.seeMaterial(params.row);
                  }
                }
              }, '课件'))
              return operationButtons;
            }
          }
        ],
        dataList:[],
      },


    }
  },
  beforeCreate() {//beforeCreate创建前状态

  },
  created() {//created创建完毕状态

  },
  beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

  },
  mounted() {//mounted 挂载结束状态
    let that = this;
    that.$refs.wzTbale.tableLoading = true;

    //运输企业
    that.axios.post(that.apiUrl.coreDeptConfigCoreDeptConfigList, {}).then(res => {
      if (!!res) {
        that.subDeptList = res.data.data;

        that.formDataSearch = {
          deptUuid : that.subDeptList[0].deptUuid,
          deptName:that.subDeptList[0].deptName,
          wzCreateYear : new Date(),
          createYear:that.public.timeFormatting(new Date(), "yyyy"),
          planTransportType:that.subDeptList[0].deptTransportCode,
        }
        that.tableData.dataList = [];
        if(!that.subDeptList[0].configMaterialSubscriptionFlag){
          that.$Message.error({
            content: '您选择的企业未授权课件，请联系运营处理。',
            duration: 3
          });
          return false;
        }
        that.tableLoadData(that.formDataSearch);
      }
    }).catch(err => {
      console.log("失败", err)
    })
  },
  methods: {//执行的方法
    tableLoadData(data){
      let that = this;
      that.$refs.wzTbale.tableLoading = true;
      that.axios.post(that.apiUrl.educateSyllabusSyllabusTrainCoursePlanList, !!data?data:{}).then(res => {
        that.$refs.wzTbale.tableLoading = false;
        if (!!res) {
          that.tableData.dataList = res.data.data;
        }
      }).catch(err => {
        console.log("失败", err)
      })
    },
    searchSubmit(data) {//搜索
      let that = this;
      that.$refs[data].validate((valid) => {
        if (valid) {
          let deptData = that.subDeptList.filter(item => that.formDataSearch.deptUuid == item.deptUuid)[0];
          that.tableData.dataList = [];
          if(!deptData.configMaterialSubscriptionFlag){
            that.$Message.error({
              content: '您选择的企业未授权课件，请联系运营处理。',
              duration: 3
            });
            return false;
          }
          that.formDataSearch.deptName = deptData.deptName
          that.formDataSearch.createYear = !!that.formDataSearch.wzCreateYear?that.public.timeFormatting(that.formDataSearch.wzCreateYear, "yyyy"):''
          that.formDataSearch.planTransportType = deptData.deptTransportCode;
          that.tableLoadData(that.formDataSearch);
        }else {
          that.$Message.error('请正确填写表单');
        }
      })
    },
    //查看课件
    seeMaterial(data) {
      let that = this;
      that.materialList = [];
      that.spinShow = true;
      that.axios.post(that.apiUrl.educateMaterialTrainMaterialTrainList, {uuids: data.trainCoursePlanMaterialUuids}).then(res => {
        if (!!res) {
          res.data.data.forEach(function (k, i) {
            let data = {};
            data.name = k.materialTrainName;//名称
            data.typeName = k.materialTrainDirectionName;//类型
            data.time = k.trainCoursePlanTaskDuration;//时长
            if (k.materialTrainType == 1) {//视频
              data.type = 1;
              data.videoSdUrl = k.materialTrainVideoSdUrl;//标清：SD
              if (!!k.materialTrainVideoHdUrl) {//高清：HD
                data.videoHdUrl = k.materialTrainVideoHdUrl;
              }
              if (!!k.materialTrainVideoFdUrl) {//超清：FD
                data.videoFdUrl = k.materialTrainVideoFdUrl;
              }
            } else {
              data.type = 2;
              data.htmlUrl = k.materialTrainHtmlUrl;//文件路径
              data.mp3Url = k.materialTrainMp3Url;//mp3路径
            }
            that.materialList.push(data);
          })
          if (!!data.materialExamUuid) {
            that.materialList.push({
              name: data.materialExamName,
              type: 3,
              id: data.materialExamUuid,
              typeName: data.trainCoursePlanDirectionName,
            });

            that.materialType = true;
            that.spinShow = false;
          } else {
            that.materialType = true;
            that.spinShow = false;
          }

        }
      }).catch(err => {
        console.log('失败', err);
      })
    },
    //大纲详情
    trainingSyllabusDailyTrai(){
      let that = this;
      if(that.tableData.dataList.length > 0){
        that.DailyTraiType = true;
      }else{
        that.$Message.error({
          content: '该企业未查询到大纲计划',
          duration: 3
        });
      }

    },
  },
  watch: {//监听

  },
  beforeUpdate() {//beforeUpdate 更新前状态

  },
  updated() {//updated 更新完成状态

  },
  beforeDestroy() {//beforeDestroy 销毁前状态

  },
  destroyed() {//destroyed 销毁完成状态

  }
}
</script>
<style lang="less">
._wz_trainingSyllabus {
  height: 100%;
  display: flex;
  flex-direction: column;

}
</style>
